package com.gmail.mariska.martin.server;

import com.gmail.mariska.martin.server.intf.IWebActionDS;
import com.gmail.mariska.martin.server.intf.IWebActionJson;
import com.gmail.mariska.martin.server.intf.Request;
import com.gmail.mariska.martin.server.intf.Response;

public class WebActionInterfaceSwitcherContainer implements IWebActionContainer {

	private final Object internalWebAction;

	public WebActionInterfaceSwitcherContainer(Object webAction) {
		internalWebAction = webAction;
	}

	@Override
	public String handle(Request request, Response response) {
		if (internalWebAction instanceof IWebActionJson) {
			IWebActionJson actJson = (IWebActionJson) internalWebAction;
			return actJson.handleJson(request.toString());
		}
		if (internalWebAction instanceof IWebActionDS) {
			IWebActionDS actDs = (IWebActionDS) internalWebAction;
			return actDs.handleDS((String) request.getParams().get("ds"));
		}
		throw new IllegalStateException("Web action hasn't any known handle interface.");
	}
}
